import { User } from '@entity/user';
import { Axios } from '@axios/base'
import { HttpStatus } from '@axios/base/http_status';

export class UserUpdate extends Axios {

    constructor() {
        super('user/update');
    }
    
    /**
     * POST /user/update/base
     * 更新用户的基本信息
     * @param user 用户
     */
    async base(user: User): Promise<Boolean> {
        const result = await this.post<Boolean>('/base', {
            id: user.id,
            name: user.name.encrypt(),
            signature: user.signature.encrypt(),
            gender: user.gender.encrypt(),
        });
        return result.status == HttpStatus.SUCCESS ? result.data : false;
    }
    
    /**
     * POST /user/update/bind
     * 更新用户的绑定信息
     * @param user 用户
     */
    async bind(user: User): Promise<Boolean> {
        const result = await this.post<Boolean>('/bind', {
            id: user.id,
            tel: user.tel.encrypt(),
            qq: user.qq.encrypt(),
            wechat: user.wechat.encrypt(),
            email: user.email.encrypt(),
        });
        return result.status == HttpStatus.SUCCESS ? result.data : false;
    }
    
    /**
     * POST /user/update/password
     * 更新用户的密码
     * @param id 用户 id
     * @param password 密码
     */
    async password(id: number, password: string): Promise<Boolean> {
        const result = await this.post<Boolean>('/password', {
            id: id,
            password: password.encrypt(),
        });
        return result.status == HttpStatus.SUCCESS ? result.data : false;
    }
    
    /**
     * POST /user/update/goodness
     * 更新用户的绑定信息
     * @param id 用户 id
     * @param goodness 用户强项
     */
    async goodness(id: number, goodness: Array<string>): Promise<Boolean> {
        const result = await this.post<Boolean>('/goodness', {
            id: id,
            goodness: goodness
        });
        return result.status == HttpStatus.SUCCESS ? result.data : false;
    }
    
    /**
     * POST /user/update/notify
     * 更新消息通知
     * @param user 用户
     */
    async notify(user: User): Promise<Boolean> {
        const result = await this.post<Boolean>('/notify', {
            id: user.id,
            systemMsg: user.systemMsg,
            privateMsg: user.privateMsg,
            groupMsg: user.groupMsg
        });
        return result.status == HttpStatus.SUCCESS ? result.data : false;
    }

}